//
//  Team.m
//  tp1-gti350
//
//  Created by Coulon-Hamelin, Alexandre on 13-09-19.
//  Copyright (c) 2013 Coulon-Hamelin, Alexandre. All rights reserved.
//

#import "Team.h"

@implementation Team

-(id)init
{
    self.players = [[NSMutableArray alloc] init];
    
    return self;
}

- (Player *)getPlayerByNumber :(int) number
{
    Player * playerToReturn;
    
    for(int i=0 ; i< [self.players count]; i++ )
    {
        Player *player = (Player *)[self.players objectAtIndex:i];
        int tmpPlayerNumber = player.number;
        if( tmpPlayerNumber == number)
        {
            playerToReturn = player;
        }
    }
    return playerToReturn;
    
}
- (BOOL) isValidPlayerNumber:(int) number
{
    BOOL response = FALSE;
    
    for(int i=0 ; i< [self.players count]; i++ )
    {
        
        Player *player = (Player *)[self.players objectAtIndex:i];
        if(player.number == number)
        {
            response = YES;
            break;
        }
    }
    return response;
}

- (NSMutableArray *)getFormatedPlayerList
{
    NSMutableArray * listToReturn = [NSMutableArray array];
    
    for(int i=0 ; i< [self.players count]; i++ )
    {
        Player *player = (Player *)[self.players objectAtIndex:i];
        NSString *number = [NSString stringWithFormat:@"%d",player.number];
        NSString *formatedString = [NSString stringWithFormat:@"%@ - %@ %@",number,player.firstName,player.lastName];
        [listToReturn addObject:formatedString];
    }
    return listToReturn;
}

- (NSString *)getOneStringFormatedPlayerList
{
    NSString * stringToReturn = [NSString string];
    
    for(int i=0 ; i< [self.players count]; i++ )
    {
        Player *player = (Player *)[self.players objectAtIndex:i];
        NSString *number = [NSString stringWithFormat:@"%d",player.number];
        NSString *formatedString = [NSString stringWithFormat:@"%@ - %@ %@",number,player.firstName,player.lastName];
        
        if (i==0)
        {
            stringToReturn = [stringToReturn stringByAppendingString: formatedString];
        }
        else
        {
            stringToReturn = [stringToReturn stringByAppendingString: [NSString stringWithFormat:@"%@%@", @"\r\r",formatedString]];
        }
    }
    
    return stringToReturn;
}

@end
